<?php
putenv("TZ=US/Pacific");

//Is there a table named $table in this database
function table_exists ($table, $db) { 
  $tables = mysql_query("SHOW TABLES FROM ".$db); 
  while (list ($temp) = mysql_fetch_array ($tables)) {
  /* printf("test2 %s\n", $temp); */
    if ($temp == $table) {
      return TRUE;
    }
  }
  return FALSE;
}

function connect_select_test ($table) {
  global $hostname, $username, $password, $database;

  //Connected to the database
  $con = mysql_connect($hostname,$username,$password);
  if (!$con)
  {
    printf("<script type='text/javascript'> setInterval(function() {window.location = 'http://www.southhillcalvary.org/siteDown.php';}, 2000); </script>");
    printf("host:%s user:%s data:%s\n", $hostname, $username, $database);
    die('Could not connect: ' . mysql_error());
  }

  //Select the database
  $db_selected = mysql_select_db($database, $con);
  if (!$db_selected)
  {
    die ("Can't use $database : " . mysql_error());
  }

  //Does table exist
  if (!table_exists($table, $database)) {
    die("Query failed " . mysql_error());
  }
}
?>
